﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class ListLibraryImage : System.Web.UI.UserControl
    {
        public int count = 1;
        public static int idCat = 0;
        DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Cate1.Items.Clear();
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTable("tbl_CategoryAnh");
                ListItem lt = new ListItem();
                int catid = Convert.ToInt32(dt.Rows[0]["CategoryAnh_ID"].ToString());
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lt = new ListItem(dt.Rows[i]["CategoryAnh_TieuDe"].ToString(), dt.Rows[i]["CategoryAnh_ID"].ToString());
                    Cate1.Items.Add(lt);
                }
                dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_ThuVienAnh", "CategoryAnh_ID", catid.ToString());
                rpt_banner.DataSource = dt;
                rpt_banner.DataBind();
                count = 1;
            }

        }

        protected void rpt_banner_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_ThuVienAnh", "ThuVienAnh_ID", id.ToString());
                Response.Redirect("/Admin/Index.aspx?panel=5&sub=12");
            }
        }

        protected void Cate1_SelectedIndexChanged(object sender, EventArgs e)
        {
            count = 1;
            int index = Cate1.SelectedIndex;
            if (index > 0)
            {
                int id = Convert.ToInt32(Cate1.SelectedValue);
                dt = DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_ThuVienAnh", "*", "CategoryAnh_ID", id, "selectwhereid");
                rpt_banner.DataSource = dt;
                rpt_banner.DataBind();
            }
            idCat = 2;
        }
    }
}